﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySkiPatrolEntity;
using MySkiPatrolDAL;
using MySkiPatrolVAL;

namespace MySkiPatrolBLL
{
    public class EventBLO
    {
        private EventDAO dao = new EventDAO();
        private EventVLO val = new EventVLO();

        public EventCollection GetEvents(Event data)
        {
            return dao.GetEvents(data);
        }

        public EventCollection GetPublicEvents(Event data)
        {
            return dao.GetPublicEvents(data);
        }

        public Event GetEvent(Event calendarEvent)
        {
            return dao.GetEvent(calendarEvent);
        }

        public Event PutEvent(Event calendarEvent)
        {
            calendarEvent = val.Validate(calendarEvent);

            switch (calendarEvent.DataTransaction.Action)
            {
                case DataAction.Add:
                    calendarEvent = dao.AddEvent(calendarEvent);
                    break;
                case DataAction.Update:
                    calendarEvent = dao.UpdateEvent(calendarEvent);
                    break;
                case DataAction.Delete:
                    calendarEvent = dao.DeleteEvent(calendarEvent);
                    break;
                default:
                    break;
            }



            //TODO: Email Engine!!!
            //if (calendarEvent.EmailBroadcast)
            //{
            //    BSPService.DataAccess.DataTables thisDAO = new BSPService.DataAccess.DataTables();

            //    List<EmailAddress> toList = thisDAO.GetEmailAddressesForBroadcast(BSPService.DataAccess.DataTables.BroadcastType.Events);
            //    EmailEngine email = new EmailEngine();

            //    foreach (EmailAddress to in toList)
            //    {
            //        email.SendEmail(calendarEvent, to.SmtpAddress, "Event - " + calendarEvent.Title, "", true, EmailEngine.EmailTemplate.EventBroadcast);
            //    }
            //}

            return calendarEvent;

        }
    }
}